import { _decorator, Component, Sprite, SpriteAtlas } from 'cc';
import { KKAnimator, KKAnimeHub } from './lib/kakera-cocos/scripts/Animator';
import { createNode } from './Common';
import { A_STAND, D_RIGHT } from './lib/kakera-cocos/scripts/Constants';
const { ccclass } = _decorator;

@ccclass('AnimeController')
export class AnimeController extends Component {

    //config

    hub:KKAnimeHub;

    atlas:SpriteAtlas;

    //init

    animator:KKAnimator;
    
    init(){
        //animator
        const spriteNode = createNode();
        this.node.addChild(spriteNode);
        const sprite = spriteNode.addComponent(Sprite);
        this.animator = new KKAnimator(this.hub,this.atlas,spriteNode,sprite);
        //init
        this.animator.setDirectionAction({direction:D_RIGHT,action:A_STAND})
    }

    render(dt:number){
        this.animator.render(dt);
    }
}
